import pymongo


def getClient():
    client = pymongo.MongoClient(host='localhost', port=27017)
    return client


def closeClient(client):
    client.close()


def insertContent(insert_content):
    client = getClient()
    db = client.cov
    collection = db.ClusterData
    result = collection.insert_one(insert_content)
    closeClient(client)
    return result


def getContent(arg):
    client = getClient()
    db = client.cov
    collection = db.ClusterData
    result = collection.find_one({'time': arg})
    closeClient(client)
    return result


def insertRegisContent(insert_content):
    client = getClient()
    db = client.cov
    collection = db.RegisData
    result = collection.insert_one(insert_content)
    closeClient(client)
    return result


def getRegisContent(arg):
    client = getClient()
    db = client.cov
    collection = db.RegisData
    result = collection.find_one({'time': arg})
    closeClient(client)
    return result
